import React from "react";
import { Descriptions, Button, Cascader, Col, Divider, Form, Input, Menu, Row, Select, Modal, Layout, Collapse } from 'antd/lib';
import { BrowserRouter as Router, Link } from 'react-router-dom';//
import LookTable from "@/components/contract/new/LookTable";
import Enums from "@/services/enums";
import Customer from "@/services/customer";
import Contracts from "@/services/contracts";
import moment from "moment";
import CheckDialog from "@/components/workflow/CheckDialog";
import { currentUser } from "@/services/auth";
import DatePicker from "antd/lib/date-picker";
import locale from 'antd/es/date-picker/locale/zh_CN';
import { createBrowserHistory } from 'history'
import LookTimeLine from "@/components/contract/new/LookTimeLine";
import Lookcheck from "@/components/contract/new/Lookcheck";
import Lookchecksqb from "@/components/contract/new/Lookchecksqb";
import Lookchecksqbdata from "@/components/contract/new/Lookchecksqbdata";
import LookAmount from "@/components/contract/new/LookAmount";
import LookTemplate from "@/components/contract/new/LookTemplate";
import notification from "@/services/notification";
import ContractApply from "@/services/contractapply";
import { get } from "lodash";
import CreateLinkBillDialog from "@/components/contract/LinkBillDialog";
import Dropdown from "antd/lib/dropdown";
import jsPDF from 'jspdf';
import html2canvas from 'html2canvas'
import Workflow from "@/services/workflow";
import Workflow_state from "@/services/workflow_state";
import WarningOutlined from "@ant-design/icons/WarningOutlined";
import DownOutlined from "@ant-design/icons/DownOutlined";
import LookTemplatetext from '@/components/contract/new/LookTemplatetext'
import GlobalFunctions from '@/store/globalFunctions';
import Cookies from 'js-cookie';
import "./Looktoolbar.less";
//import watermark from 'water-mark-oc'
// const imagePath = require('./imagePath.png')
// const logoPath = require('./logoPath.png')
// import Template from "@/components/contract/new/Template";
const customHistory = createBrowserHistory();
const { confirm } = Modal;
const { Content, Sider } = Layout;
const { Panel } = Collapse;

export default class LookToolbar extends React.Component {
  state = {
    loading: true,
    isnew: true,
    id: 0,
    isedit: true,
    isdel: false,
    openpage: currentUser.orgunit_id === 0 ? "htzw" : "jbxx",
    template_value: '',
    userid: currentUser.id,//--操作员ID
    bill_date: moment(),//--日期
    created_at: moment(),
    employeeid: "",//--经办人
    employeename: "",
    departmentname: "",
    typename: "",
    party_aname: "",
    templatename: "",
    partybname: "",
    partybmobile: "",
    party_representative: "",
    party_mobile: "",
    party_address: "",
    departmentid: 0,//--经办部门
    code: "",//----合同编号
    name: "",//--合同名称
    type: "",//--合同类别
    party_aid: "",//--甲方ID
    party_bid: "",//--乙方
    party_cid: "",//--其它关联方
    pay_direction: 0,//,--收付方向0-fukuan,1-shoukuan
    infrastructure: 0,
    pricetype: 0,
    sign_date: moment(),//--合同签订日期
    start_date: moment(),//--合同开始日期
    end_date: moment(),//--合同终止日期
    warn_date: moment(),
    warn_checkdate: moment(),
    warn_message: '',
    warn_check: '',
    amount: "0",//--金额
    amount_words: "",//----合同金额(大写)
    zhengcai: 0,//0非政采，1政采
    iskeyan: 0,
    isbulu: 0,//0正常，1补录
    amounttype: "",
    contracttype: [],
    status: 0,//--状态
    message: "",//--纪录事项
    sourcetype: "",
    sourceid: 0,
    officialcode: "",
    budgetcode: "",
    recordcode: "",
    username: "",
    templateid: "1",
    templatecontent: "",
    customerdata: [],//供应商表HRP
    employeedata: [],//HRP职员表
    departmentdata: [],//HRP部门表
    pay_directiondata: [{ id: 0, name: "收款" },
    { id: 1, name: "付款" }, { id: 2, name: "非经济" }],
    pricetypedata: [{ id: 0, name: "总价合同" },
    { id: 1, name: "单价合同" }, { id: 2, name: "费率合同" },{id:3,name:"成本补偿"},{id:4,name:"绩效激励"}],
    isCreatecontractEnabled: true,
    // curl:"./imagePath.png",
    bytseal: false,
    bytrecord: false,
    urlseal: '',
    urlrecord: '',
    checkmessage: "<div>同意</div>",
    workflow_state: "",
    organizationname: "成都市第六人民医院",
    tablefielddata: [{ code: 'code', name: "预编码" }],
    elementdata: "",
    empowerduties:"",
    empowerperson:"",
    empowersex:"",
    iszhaobiao:0,
    warnsealusername:"",
  };

  componentWillMount() {
    Customer.query(2).then(data => {
      this.setState({
        customerdata: data,
      });
    });
    //HRP职员表
    let params = {
      code: "",
      name: "",
      userid: currentUser.id,
    }
    Customer.queryemployee(params).then(data => {
      this.setState({
        employeedata: data,
      });
    });
    //HRP部门表
    params = {
      code: "",
      name: "",
      userid: currentUser.id,
    }
    Customer.querydepartment(params).then(data => {
      this.setState({
        departmentdata: data,
      });
    });
    params = {
      page: 1,
      pagesize: 100,
      tablename: 'contracts',
    }
    Workflow_state.getcollist(params).then(data => {
      this.setState({
        tablefielddata: data.data,
      });
    });
    if (this.props.id > 0) {
      this.setState({
        id: this.props.id,
        isnew: false,
        loading: false,
      });
      this.refreshData(this.props.id);
      this.iseditData(this.props.id);
    }
  }

  refreshData(id = 0) {
    let params = {
      page: 1,
      pagesize: 2,
      code: '',
      name: '',
      party_a: '',
      type: '',
      userid: '',
      id: id,
      departmentid: [],
      amount: 0,
      amountmax: 0,
      datadown: false,
    }
    Contracts.getlist(params).then(da => {
      if (da.data.length > 0) {
        let data = da.data[0];
        let checkmessage = Cookies.get('contract' + data.userid + data.id + data.workflow_state)
        if (GlobalFunctions.isEmptyobj(checkmessage)) {
          checkmessage = "";
        }
        this.getelementdata(data);
        this.setState({
          id: data.id,//
          userid: data.userid,//--操作员ID
          bill_date: moment(data.bill_date),//--日期
          created_at: moment(data.created_at),
          employeeid: data.employeeid,//--经办人
          departmentid: data.departmentid,//--经办部门
          code: data.code,//----合同编号
          name: data.name,//--合同名称
          type: data.type,//--合同类别
          party_aid: data.party_aid,//--甲方ID
          party_bid: data.party_bid,//--乙方
          party_cid: data.party_cid,//--其它关联方
          pay_direction: data.pay_direction,//,--收付方向0-fukuan,1-shoukuan
          infrastructure: data.infrastructure,
          pricetype: data.pricetype,
          sign_date: GlobalFunctions.isEmptyobj(data.sign_date) ? null : moment(data.sign_date),//--合同签订日期
          start_date: GlobalFunctions.isEmptyobj(data.start_date) ? null : moment(data.start_date),//--合同开始日期
          end_date: GlobalFunctions.isEmptyobj(data.end_date) ? null : moment(data.end_date),//--合同终止日期
          warn_date: GlobalFunctions.isEmptyobj(data.warn_date) ? null : moment(data.warn_date),
          warn_checkdate: GlobalFunctions.isEmptyobj(data.warn_checkdate) ? null : moment(data.warn_checkdate),
          warn_message: data.warn_message,
          warn_check: data.warn_check,
          amount: data.amount,//--金额
          amount_words: data.amount_words,//----合同金额(大写)
          zhengcai: data.zhengcai,//0非政采，1政采
          iskeyan: data.iskeyan,
          isbulu: data.isbulu,//0正常，1补录
          amounttype: data.amounttype,
          contracttype: data.contracttype,
          status: data.status,//--状态
          officialcode: data.officialcode,
          budgetcode: data.budgetcode,
          recordcode: data.recordcode,
          username: data.username,
          templateid: data.templateid,
          templatecontent: data.templatecontent,
          employeename: data.stremployeename,
          departmentname: data.orgname,
          typename: data.typename,
          party_aname: data.partyaname,
          templatename: data.templatename,
          partybname: data.partybname,
          party_representative: data.party_representative,
          party_mobile: data.party_mobile,
          partybmobile: data.partybmobile,
          party_address: data.party_address,
          message: data.message,//--纪录事项
          loading: false,
          bytseal: false,
          bytrecord: false,
          urlseal: '',
          urlrecord: '',
          sourcetype: data.ctype,
          workflow_state: data.workflow_state,
          checkmessage: checkmessage,
          organizationname: data.organizationname,
          empowerduties:data.empowerduties,
          empowerperson:data.empowerperson,
          empowersex:data.empowersex,
          iszhaobiao:data.iszhaobiao,
          warnsealusername:data.warnsealusername,
        });
      } else {
        this.setState({
          loading: false,
          id: id,
          userid: currentUser.id,//--操作员ID
          bill_date: moment(),//--日期
          created_at: moment(),
          employeeid: "",//--经办人
          departmentid: 0,//--经办部门
          code: "",//----合同编号
          name: "",//--合同名称
          type: "",//--合同类别
          party_aid: "",//--甲方ID
          party_bid: "",//--乙方
          party_cid: "",//--其它关联方
          pay_direction: 0,//,--收付方向0-fukuan,1-shoukuan
          infrastructure: 0,
          pricetype: 0,
          sign_date: moment(),//--合同签订日期
          start_date: moment(),//--合同开始日期
          warn_date: moment(),
          warn_checkdate: moment(),
          end_date: moment(),//--合同终止日期
          warn_message: '',
          warn_check: '',
          amount: "0",//--金额
          amount_words: "",//----合同金额(大写)
          zhengcai: 0,//0非政采，1政采
          iskeyan: 0,
          isbulu: 0,//0正常，1补录
          amounttype: "",
          contracttype: [],
          status: 0,//--状态
          officialcode: "",
          budgetcode: "",
          recordcode: "",
          username: "",
          templateid: "1",
          templatecontent: "",
          message: "",//--纪录事项
          employeename: "",
          departmentname: "",
          typename: "",
          party_aname: "",
          templatename: "",
          partybname: "",
          party_representative: "",
          party_mobile: "",
          partybmobile: "",
          party_address: "",
          bytseal: false,
          bytrecord: false,
          urlseal: '',
          urlrecord: '',
          sourcetype: '',
          workflow_state: "",
          checkmessage: "",
          organizationname: "",
          empowerduties:"",
          empowerperson:"",
          empowersex:"",
          iszhaobiao:0,
          warnsealusername:"",
        });
      }
    }).catch(error => {
      this.setState({
        loading: false,
        id: id,
        userid: currentUser.id,//--操作员ID
        bill_date: moment(),//--日期
        created_at: moment(),
        employeeid: "",//--经办人
        departmentid: 0,//--经办部门
        code: "",//----合同编号
        name: "",//--合同名称
        type: "",//--合同类别
        party_aid: "",//--甲方ID
        party_bid: "",//--乙方
        party_cid: "",//--其它关联方
        pay_direction: 0,//,--收付方向0-fukuan,1-shoukuan
        infrastructure: 0,
        pricetype: 0,
        sign_date: moment(),//--合同签订日期
        start_date: moment(),//--合同开始日期
        end_date: moment(),//--合同终止日期
        warn_date: moment(),
        warn_checkdate: moment(),
        warn_message: '',
        warn_check: '',
        amount: "0",//--金额
        amount_words: "",//----合同金额(大写)
        zhengcai: 0,//0非政采，1政采
        iskeyan: 0,
        isbulu: 0,//0正常，1补录
        amounttype: "",
        contracttype: [],
        status: 0,//--状态
        officialcode: "",
        budgetcode: "",
        recordcode: "",
        username: "",
        templateid: "1",
        templatecontent: "",
        message: "",//--纪录事项
        bytseal: false,
        bytrecord: false,
        urlseal: '',
        urlrecord: '',
        sourcetype: '',
        workflow_state: "",
        checkmessage: "",
        organizationname: "",
        empowerduties:"",
        empowerperson:"",
        empowersex:"",
        iszhaobiao:0,
        warnsealusername:"",
      });
    });
  }

  getelementdata = (items) => {
    let params = {
      bill: "contracts",
      billid: this.state.id,
      typeid: 1,
    }
    Workflow.getcheckmessag(params).then(data => {
      let params = {
        bill: "contracts",
        billid: items.id,
        organizationname: items.organizationname,
        name: items.name,
        officialcode: items.officialcode,
        party_aname: items.partyaname,
        party_bname: items.partybname,
        party_mobile: items.party_mobile,
        pricetype: items.pricetype,
        amount: items.amount,
        amount_words: items.amount_words,
        contracttype: items.contracttype,
        message: items.message,
        employeename: items.stremployeename,
        empowerperson: items.empowerperson,
        empowerduties: items.empowerduties,
        data: data,
      }
      let elementdata = Lookchecksqbdata.getDatas(params);
      this.setState({
        elementdata: elementdata,
      });
    });
  }

  ///|| str.match(/^[\s]*$/)
  isEmptyobj = (str) => {
    if (str === '' || str === null || str === 'null' || str === undefined || str === 'undefined') {
      return true;
    } else {
      return false;
    }
  }

  handleupdate = () => {
    // if(this.state.status===2 ){
    //     return (<Router  history={customHistory}>
    //         <Link to={`/contract/change/new/${this.state.id}`}>变更</Link>
    //      </Router>);
    //   }else{
    return (<Router history={customHistory}>
      <Link style={{ margin: "20px" }} to={`/contract/new/${this.state.id}`}>
        <font size="5">编辑</font> </Link>
    </Router>);
    // }
  };
  handlebackpage = () => {
    customHistory.goBack();
  };
  handleCheck = () => {
    if (!currentUser.isAudit) {
      if (this.state.status === 0 || (this.state.status === 1 && this.state.userid === currentUser.id)) {

      } else {
        notification.error("没有权限.");
        return;
      }
    }
    let checkmessage = this.state.checkmessage;
    if (this.state.openpage === "htzw") {
      checkmessage = this.childtemplate.state.checkmessage;//.toHTML();
    }
    let item = {
      bill: "contracts",
      billid: this.state.id,
      billtype: 0,
      next_type: 1,
      message: checkmessage,
      userid: currentUser.id,
      billdate: this.state.bill_date.format('YYYY-MM-DD'),
      orgunitid: this.state.departmentid,
      status: this.state.status,
      altermsg: this.state.warn_check,
      warnsealuser:"",
      billuserid: this.state.userid,
    }
      // item = {
      //   bill: "contracts",
      //   billtype: 0,
      //   billid: this.state.id,
      //   next_type: 1,
      //   message: '<div>同意</div>',
      //   userid: currentUser.id,
      //   billdate: this.state.bill_date.format('YYYY-MM-DD'),
      //   orgunitid: this.state.departmentid,
      //   status: this.state.status,
      // }
      CheckDialog.showModal({ bill_check: item })
        .onClose((result = {}) => {
          if (result.success) {
            this.iseditData(this.state.id);
            this.refreshData(this.state.id)
            // this.setState({
            //   id: item.id,
            // });
          }
        }).onDismiss(() => {
          //     navigateTo("contract/apply", true);
        });
    // }
  };
  iseditData(id) {
    let item = {
      bill: "contracts",
      billtype: 0,
      billid: id,
      userid: currentUser.id
    }
  };
  childchange2 = (data) => {
    Cookies.set('contract' + this.state.userid + this.state.id + this.state.workflow_state, data.checkmessage, { expires: 1 });
    this.setState({
      checkmessage: data.checkmessage,
    });
  };

  handledown = () => {
    let AjaxUrl = 'api/upload/htmltopdf';
    if (this.state.templateid === 0) {
      AjaxUrl = 'api/upload/wordtopdf';

    }
    fetch(AjaxUrl, {
      method: 'POST',
      body: window.JSON.stringify({ filename: '合同正文' + this.state.code, filetype: 1, file: this.state.templatecontent }),
      credentials: 'include',
      headers: new Headers({
        'Content-Type': 'application/json'
      })
    }).then((response) => {
      response.blob().then(blob => {
        const aLink = document.createElement('a');
        document.body.appendChild(aLink);
        aLink.style.display = 'none';
        const objectUrl = window.URL.createObjectURL(blob);
        aLink.href = objectUrl;
        aLink.download = '合同正文' + this.state.code + '.pdf';
        aLink.click();
        document.body.removeChild(aLink);
      });
    }).catch((error) => {
      console.log(error);
    });
  };
  handleprint = (index) => {
    if (index === 0) {
      this.handledown();
    } else if (index === 1 && this.state.infrastructure === 0) {
      confirm({
        title: '请不要忘记编辑合同的签订、开始、结束日期!',
        icon: <WarningOutlined />,
        content: '',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk: () => {

          // 导出配置

          let AjaxUrl = 'api/upload/htmltopdf';

          fetch(AjaxUrl, {
            method: 'POST',
            body: window.JSON.stringify({ filename: '合同审签表' + this.state.code, filetype: 1, file: this.state.elementdata }),
            credentials: 'include',
            headers: new Headers({
              'Content-Type': 'application/json'
            })
          }).then((response) => {
            response.blob().then(blob => {
              const aLink = document.createElement('a');
              document.body.appendChild(aLink);
              aLink.style.display = 'none';
              const objectUrl = window.URL.createObjectURL(blob);
              aLink.href = objectUrl;
              aLink.download = '合同审签表' + this.state.code + '.pdf';
              aLink.click();
              document.body.removeChild(aLink);
            });
          }).catch((error) => {
            console.log(error);
          });
        },
      });
    } 
  }
  handleseal = (bill, typeid) => {
    if (bill === "contractseal") {
      if (!currentUser.isSeal) {
        notification.error("没有权限.");
        return;
      }
    } else if (bill === "contractrecord") {
      if (!currentUser.isRecord) {
        notification.error("没有权限.");
        return;
      }
    } else {
      if (!currentUser.isDefault) {
        notification.error("没有权限.");
        return;
      }
    }
    if (this.state.status !== 2) {
      notification.error("只有在审批状态可以生成下游单据，生成失败！");
      return;
    }
    confirm({
      title: '确定生成?',
      icon: <WarningOutlined />,
      content: this.state.name,
      okText: '确定',
      okType: 'danger',
      cancelText: '取消',
      onOk: () => {
        let param = {
          sourcebill: "contracts",
          sourcebillid: this.state.id,
          bill: bill,
          userid: currentUser.id,
          typeid: typeid,
        }
        ContractApply.getpushbill(param).then(data => {
          if (data[0].flag === 0) {
            notification.success("生成成功,编号：" + data[0].code);
            // let items={
            //   id:data[0].id,
            //   code:data[0].code,
            //   billname:"用印申请单",
            // }
            // this.showCreateLinkBillDialog(items);
          } else {
            notification.error("生成失败:" + data[0].code);
          }
        }).catch(error => {
          notification.error(get(error, "response.data.message", "生成失败."));
        });
      },
    });
  };
  showCreateLinkBillDialog = (items) => {
    CreateLinkBillDialog.showModal({ items: items })
      .onClose((result = {}) => {
        // if (result.success) {
        //   this.refreshData();
        // }
      }).onDismiss(() => {
        // navigateTo("orgstruct", true);
      });
  };
  tabsClick = e => {
    this.setState({
      openpage: e.key,
    });
  };
  templateSelect() {
    if (this.state.openpage === "jbxx") {//
      let strstatus;
      if (this.state.status === 0) {
        strstatus = "草稿"
      } else if (this.state.status === 1) {
        strstatus = "审核中"
      } else {
        strstatus = "已审核"
      };

      return (<div style={{ background: this.state.curl ? `url(${this.state.curl})` : '#FFFFFF' }}>
        <Collapse defaultActiveKey={['1', '2', '3']} >
          <Panel header="基本" key="1">
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>起草日期:</Col>
              <Col span={6}>
                {this.state.bill_date.format('YYYY-MM-DD')}
              </Col>
              <Col span={2}>录入日期:</Col>
              <Col span={6}>
                {this.state.created_at.format('YYYY-MM-DD')}
              </Col>
              <Col span={2}>经办部门:</Col>
              <Col span={6}>
                {this.state.departmentname}
              </Col>
            </Row>

            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>合同单位:</Col>
              <Col span={6}>
                {this.state.party_aname}
              </Col>
              <Col span={2}>合同类别:</Col>
              <Col span={6}>
                {this.state.contracttype.length < 1 ? "" : this.state.contracttype.join('，')}
              </Col>
              <Col span={2}>经办人:</Col>
              <Col span={6}>
                {this.state.employeename}
              </Col>
            </Row>
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>{this.state.tablefielddata.filter(item => item.code === 'code')[0].name}:</Col>
              <Col span={6}>
                {this.state.code}
              </Col>
              <Col span={2}>合同名称:</Col>
              <Col span={6}>
                {this.state.name}
              </Col>
              <Col span={2}>收付款类型:</Col>
              <Col span={6}>
                {this.state.pay_direction === 0 ? "收款" : (this.state.pay_direction === 1 ? "付款" : (this.state.pay_direction === 2 ? "非经济" : ""))}
              </Col>
            </Row>

            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>签订日期:</Col>
              <Col span={6}>
                {GlobalFunctions.isEmptyobj(this.state.sign_date) ? '' : this.state.sign_date.format('YYYY-MM-DD')}
              </Col>
              <Col span={2}>服务期限从:</Col>
              <Col span={6}>
                {GlobalFunctions.isEmptyobj(this.state.start_date) ? '' : this.state.start_date.format('YYYY年MM月DD日')}
                至{GlobalFunctions.isEmptyobj(this.state.end_date) ? '' : this.state.end_date.format('YYYY年MM月DD日')}
              </Col>
              <Col span={2}>资金类别:</Col>
              <Col span={6}>
                {this.state.amounttype}
              </Col>
            </Row>

            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>{this.state.pricetype === 0 ? "金额(¥)" : "预算金额(¥)"}</Col>
              <Col span={6}>
                {this.state.amount}
              </Col>
              <Col span={2}>金额(大写):</Col>
              <Col span={6}>
                {this.state.amount_words}
              </Col>
              <Col span={2}>预算编号:</Col>
              <Col span={6}>
                {this.state.budgetcode}
              </Col>
            </Row>
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>合同类型:</Col>
              <Col span={6}>
                {this.state.pricetype === 0 ? "总价合同" : (this.state.pricetype === 1 ? "单价合同" : (this.state.pricetype === 2 ? "费率合同" : (this.state.pricetype === 3 ? "成本补偿" : (this.state.pricetype === 4 ? "绩效激励" : ""))))}
              </Col>
              <Col span={2}>来源类别:</Col>
              <Col span={6}>
                {this.state.sourcetype}
              </Col>
              <Col span={2}>正式编码:</Col>
              <Col span={6}>
                {this.state.officialcode}
              </Col>
            </Row>
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>第三方:</Col>
              <Col span={6}>
                {this.state.partybname}
              </Col>
              <Col span={2}>备案号:</Col>
              <Col span={6}>
                {this.state.recordcode}
              </Col>
              <Col span={2}>录入人:</Col>
              <Col span={6}>
                {this.state.username}
              </Col>
            </Row>
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>是否集采:</Col>
              <Col span={6}>
                {this.state.zhengcai === 0 ? "否" : "是"}
              </Col>
              <Col span={2}>补录合同:</Col>
              <Col span={6}>
                {this.state.isbulu === 0 ? "否" : "是"}
              </Col>
              <Col span={2}>备案合同:</Col>
              <Col span={6}>
                {this.state.infrastructure === 0 ? "否" : "是"}
              </Col>
            </Row>
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>是否授权委托:</Col>
              <Col span={6}>
                {this.state.empowersex }
              </Col>
              <Col span={2}>授权代理人:</Col>
              <Col span={6}>
                {this.state.empowerperson }
              </Col>
              <Col span={2}>代理人职务:</Col>
              <Col span={6}>
                {this.state.empowerduties}
              </Col>
            </Row>
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>状态:</Col>
              <Col span={6}>
                {strstatus}
              </Col>
              <Col span={2}>是否科研:</Col>
              <Col span={6}>
                {this.state.iskeyan === 0 ? "否" : "是"}
              </Col>
              <Col span={2}>是否公开招标:</Col>
              <Col span={6}>
                {this.state.iszhaobiao === 0 ? "否" : "是"}
              </Col>
            </Row>
          </Panel>
          <Panel header="提醒" key="2">
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>审核提醒:</Col>
              <Col span={6}>
                {this.state.warn_check}
              </Col>
              <Col span={2}>提醒内容:</Col>
              <Col span={6}>
                {this.state.warn_message}
              </Col>
            </Row>
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>审批截止日期:</Col>
              <Col span={6}>
                {GlobalFunctions.isEmptyobj(this.state.warn_checkdate) ? '' : this.state.warn_checkdate.format('YYYY-MM-DD')}
              </Col>
              <Col span={2}>提醒日期:</Col>
              <Col span={6}>
                {GlobalFunctions.isEmptyobj(this.state.warn_date) ? '' : this.state.warn_date.format('YYYY-MM-DD')}
              </Col>
            </Row>
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>用印提醒人:</Col>
              <Col span={6}>
                {this.state.warnsealusername}
              </Col>
            </Row>
          </Panel>
          <Panel header="其它" key="3">
            <Row style={{ marginBottom: 5 }}>
              <Col span={2}>重要条款:</Col>
              <Col span={6}>
                {this.state.message}
              </Col>
            </Row>
          </Panel>
        </Collapse>
      </div>);
    } else if (this.state.openpage === "sjx") {//时间线
      return (<LookTimeLine id={this.state.id} />);
    } else if (this.state.openpage === "htzw") {//正文
      if (document.querySelector('body').offsetWidth > 600) {
        return (<div>
          <Layout>
            <Content>
              <LookTemplatetext templateid={this.state.templateid} templatename={this.state.templatename}
                templatecontent={this.state.templatecontent}
                onRef={(ref) => { this.childtemplatetext = ref; }} />
            </Content>
            <Sider width={320} style={{ background: '#fff' }}>
              <LookTemplate templateid={this.state.templateid}
                checkmessage={this.state.checkmessage} id={this.state.id}
                type={this.state.type} templatecontent={this.state.templatecontent}
                onRef={(ref) => { this.childtemplate = ref; }} childchange2={this.childchange2} />
            </Sider>
          </Layout>
        </div>);
      } else {
        return (<div>
          <LookTemplate templateid={this.state.templateid}
            checkmessage={this.state.checkmessage} id={this.state.id}
            type={this.state.type} templatecontent={this.state.templatecontent}
            onRef={(ref) => { this.childtemplate = ref; }} childchange2={this.childchange2} />
          <LookTemplatetext templateid={this.state.templateid} templatename={this.state.templatename}
            templatecontent={this.state.templatecontent}
            onRef={(ref) => { this.childtemplatetext = ref; }} />
        </div>);
      }
    } else if (this.state.openpage === "fj") {//附件
      return (<LookTable id={this.state.id} status={this.state.status} isedit={this.state.isedit} />);
    } else if (this.state.openpage === "spxx") {//审批信息
      return (<Lookcheck id={this.state.id} bill_date={this.state.bill_date.format('YYYY-MM-DD')}
        departmentid={this.state.departmentid} status={this.state.status}
        employeename={this.state.employeename}
      />);
    } else if (this.state.openpage === "sqbxx") {//审签表信息
      return (<Lookchecksqb elementdata={this.state.elementdata} 
      />);
    } else if (this.state.openpage === "kx") {//款项
      return (<LookAmount id={this.state.id} code={this.state.officialcode} />);
    }
  };
  templateChange = value => {
    this.setState({
      template_value: value
    });
  };

  render() {
    if (this.state.loading) return null;
    return (
      <div>
        <div style={{ marginBottom: 16 }}>
          <Divider type="vertical" />

          <Button type="primary" style={{ margin: "10px" }} onClick={() => this.handlebackpage()}>
            <i className="fa fa-reply m-r-5" />
            返回
          </Button>
          {currentUser.orgunit_id > 0 && (<Button type="primary" style={{ margin: "10px", width: "90px" }}><Router history={customHistory}>
            <Link style={{ margin: "10px" }}
              to={this.state.isbulu === 0 ? `/contract/new/${this.state.id}` : `/contract/bulu/${this.state.id}`}>
              <i class="fa fa-pencil-square-o m-r-5" />
              <font color="#FFFFFF">编辑</font></Link></Router>
          </Button>)}
          <Button type="primary" style={{ margin: "10px" }} onClick={() => this.handleCheck()} >
            <i className="fa fa-check m-r-5" />
            {this.state.status === 0 ? "提交" : "审核"}
          </Button>
          {this.state.status === 2 && (<Dropdown
            trigger={["click"]}
            overlay={
              <Menu>
                <Menu.Item key="change-item">
                  <a onMouseUp={() => this.handleprint(0)} disabled={this.state.status !== 2}>合同正文</a>
                </Menu.Item>
                <Menu.Divider />
                <Menu.Item key="delete-item">
                  <a onMouseUp={() => this.handleprint(1)} disabled={this.state.status !== 2}>合同审签表</a>
                </Menu.Item>
              </Menu>
            }>
            <Button type="primary" style={{ margin: "10px" }} data-test="CreateButton" >
              打印 <DownOutlined />
            </Button>
          </Dropdown>)}
          {this.state.status === 2 && (
            <Dropdown
              trigger={["click"]}
              disabled={this.state.status !== 2}
              overlay={
                <Menu>
                  <Menu.Item key="change-item">
                    <a onMouseUp={() => this.handleseal("contractchange", 0)}>变更</a>
                  </Menu.Item>
                  <Menu.Divider />
                  <Menu.Item key="delete-item">
                    <a onMouseUp={() => this.handleseal("contracts", 1)}>另签</a>
                  </Menu.Item>
                  <Menu.Divider />
                  <Menu.Item key="delete-item">
                    <a onMouseUp={() => this.handleseal("contracts", 2)}>补签</a>
                  </Menu.Item>
                </Menu>
              }>
              <Button style={{ margin: "10px" }} type="primary" data-test="CreateButton" disabled={this.state.status !== 2}>
                变更 <DownOutlined />
              </Button>
            </Dropdown>)}
          {this.state.status === 2 && (<Dropdown
            trigger={["click"]}
            overlay={
              <Menu>
                <Menu.Item key="contractseal">
                  <a onMouseUp={() => this.handleseal("contractseal", 0)}>用印</a>
                </Menu.Item>
                <Menu.Item key="contractrecord">
                  <a onMouseUp={() => this.handleseal("contractrecord", 0)} >备案</a>
                </Menu.Item>
                <Menu.Divider />
                <Menu.Item key="contractprogress">
                  <a onMouseUp={() => this.handleseal("contractprogress", 0)} >违约登记</a>
                </Menu.Item>
                <Menu.Item key="contractstop">
                  <a onMouseUp={() => this.handleseal("contractstop", 0)} >终止</a>
                </Menu.Item>
                <Menu.Item key="contractfinish">
                  <a onMouseUp={() => this.handleseal("contractfinish", 0)} >验收</a>
                </Menu.Item>
                <Menu.Item key="contractsettle">
                  <a onMouseUp={() => this.handleseal("contractsettle", 0)} >结算</a>
                </Menu.Item>
                <Menu.Divider />
                <Menu.Item key="contracts">
                  <a onMouseUp={() => this.handleseal("contracts", 0)} >续签</a>
                </Menu.Item>
              </Menu>
            }>
            <Button type="primary" style={{ margin: "10px" }} data-test="CreateButton" >
              其它 <DownOutlined />
            </Button>
          </Dropdown>)}

        </div>
        <Menu onClick={this.tabsClick} selectedKeys={this.state.openpage} mode="horizontal">
          {currentUser.orgunit_id > 0 && (<Menu.Item key="jbxx">基本信息</Menu.Item>)}
          <Menu.Item key="htzw">合同正文</Menu.Item>
          {currentUser.orgunit_id > 0 && (<Menu.Item key="fj">附件</Menu.Item>)}
          {currentUser.orgunit_id > 0 && (<Menu.Item key="spxx">审批信息</Menu.Item>)}
          {this.state.status === 2 && (<Menu.Item key="sqbxx">审签表信息</Menu.Item>)}
          {this.state.status === 2 && currentUser.orgunit_id > 0 && (<Menu.Item key="kx">款项计划</Menu.Item>)}
          <Menu.Item key="sjx">时间线</Menu.Item>
        </Menu>
        <div>
          {this.templateSelect()}
        </div>
      </div>

    );
  };
}
